package define.Demo_01.gameWZ;

import java.util.Random;

public class Player {
    private String name;
    private int blood;


    public Player() {
    }

    public Player(String name, int blood) {
        this.name = name;
        this.blood = blood;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return blood
     */
    public int getBlood() {
        return blood;
    }

    /**
     * 设置
     * @param blood
     */
    public void setBlood(int blood) {
        this.blood = blood;
    }

    public String toString() {
        return "Player{name = " + name + ", blood = " + blood + "}";
    }
    public void attack(Player player) {
        //随机伤害数值
        Random random = new Random();
        int blood = random.nextInt(20) + 1;
        //扣除血量
        player.setBlood(player.getBlood() - blood);

        System.out.println(this.getName() + "攻击" + player.getName() + "，造成" + blood + "点伤害,"+player.getName()+"剩余血量："+player.getBlood());
    }
}
